﻿using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace HabraReader
{
    public partial class CollapseButton : Button
    {
        public CollapseButton()
        {
            this.SetStyle(ControlStyles.AllPaintingInWmPaint,  true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            DrawButton(pevent.Graphics, Color.Gray, Color.Gray);
        }

        private void CollapseButtonMouseMove(object sender, MouseEventArgs e)
        {
            Graphics g = Graphics.FromHwnd(this.Handle);
            DrawButton(g, Color.LightSlateGray, Color.LightSlateGray);
        }

        private void DrawButton(Graphics g, Color start, Color end)
        {
            var borderPen = new Pen(Color.Black, 1);
            var baseBrush = new LinearGradientBrush(
                new Point(0, 0), new Point(Width, Height), start, end);
            g.FillRectangle(baseBrush, ClientRectangle);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            var dotsBrush = new LinearGradientBrush( 
                new Point(0, 0), new Point(Width, Height), Color.Black, Color.Gray);
            g.FillEllipse(dotsBrush, Width / 2 - 2, Height / 2, 3, 3);
            g.FillEllipse(dotsBrush, Width / 2 - 2, Height / 2 + 8, 3, 3);
            g.FillEllipse(dotsBrush, Width / 2 - 2, Height / 2 + -8, 3, 3);
            g.DrawLine(borderPen, 0, 0, 0, Height - 1);
            g.DrawLine(borderPen, Width - 1, 0, Width - 1, Height - 1);
            borderPen.Dispose();
            baseBrush.Dispose();
            dotsBrush.Dispose();
        }
    }
}